package com.fled.itsmbigscreen.controller;

import com.fled.itsmbigscreen.dto.FindHighBugClient.FindHighBugClientDto;
import com.fled.itsmbigscreen.dto.GroupAddDto;
import com.fled.itsmbigscreen.dto.GroupDelDto;
import com.fled.itsmbigscreen.dto.GroupEditNameDto;
import com.fled.itsmbigscreen.dto.clientInfoDto.ClientListDto;
import com.fled.itsmbigscreen.dto.clientListDto.ClientListData;
import com.fled.itsmbigscreen.dto.groupDto.HuorongBaseList;
import com.fled.itsmbigscreen.response.BaseResult;
import com.fled.itsmbigscreen.response.RetResponse;
import com.fled.itsmbigscreen.service.HuorongService;
import com.fled.itsmbigscreen.service.TaskService;
import com.fled.itsmbigscreen.service.impl.TaskImpl;
import com.fled.itsmbigscreen.vo.DefVo;
import com.fled.itsmbigscreen.vo.GroupAddVo;
import com.fled.itsmbigscreen.vo.getDefCenter;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(description = "火绒接口")
@CrossOrigin
@RequestMapping("/Huorong")
@RestController
public class HuorongController {


    @Autowired
    private HuorongService huorongService;
    @Autowired
    private TaskService taskService;



    @ApiOperation("获取所有分组")
    @GetMapping("/GroupList")
    @ResponseBody
    public BaseResult GroupList() {
        try {
            HuorongBaseList huorongBaseList = huorongService.GroupList();
            return RetResponse.makeOKRsp(huorongBaseList);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    @ApiOperation("创建分组")
    @PostMapping("/GroupAdd")
    @ResponseBody
    public BaseResult GroupAdd(@RequestBody GroupAddDto groupAddDto ) {
        try {
            GroupAddVo groupAddVo = huorongService.GroupAdd(groupAddDto);
            return RetResponse.makeOKRsp(groupAddVo);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }


    @ApiOperation("删除分组")
    @PostMapping("/GroupDel")
    @ResponseBody
    public BaseResult GroupDel(@RequestBody GroupDelDto groupDelDto ) {
        try {
            huorongService.GroupDel(groupDelDto);
            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    @ApiOperation("编辑分组名称")
    @PostMapping("/GroupEditName")
    @ResponseBody
    public BaseResult GroupEditName(@RequestBody GroupEditNameDto groupEditNameDto ) {
        try {
            huorongService.GroupEditName(groupEditNameDto);
            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }



    @ApiOperation("获取所有设备详情")
    @GetMapping("/ClientListWithInfo")
    @ResponseBody
    public BaseResult ClientListWithInfo(Integer pageNum,Integer pageSize) {
        try {
            ClientListDto clientList = huorongService.ClientListWithInfo(pageNum,pageSize);
            return RetResponse.makeOKRsp(clientList);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }


    @ApiOperation("获取所有设备列表")
    @GetMapping("/ClientList")
    @ResponseBody
    public BaseResult ClientList(Integer pageNum,Integer pageSize) {
        try {
            ClientListData clientList = huorongService.ClientList(pageNum,pageSize);
            return RetResponse.makeOKRsp(clientList);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }


    @ApiOperation("根据clientIds获取设备详情")
    @GetMapping("/ClientInfo")
    @ResponseBody
    public BaseResult ClientInfo(String clientIds) {
        try {
            ClientListDto clientList = huorongService.clientIds(clientIds);
            return RetResponse.makeOKRsp(clientList);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    @ApiOperation("根查询存在高危漏洞未修复的终端")
    @GetMapping("/findHighBugClient")
    @ResponseBody
    public BaseResult findHighBugClient(Integer pageNum,Integer pageSize) {
        try {
            FindHighBugClientDto clientList = huorongService.findHighBugClient(pageNum,pageSize);
            return RetResponse.makeOKRsp(clientList);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    @ApiOperation("查询今日防御数量")
    @GetMapping("/getDefNum")
    @ResponseBody
    public BaseResult getDefNum() {
        try {
            int num = huorongService.getDefNum();
            return RetResponse.makeOKRsp(num);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }


    @ApiOperation("查询防护中心")
    @GetMapping("/getDefCenter")
    @ResponseBody
    public BaseResult getDefCenter() {
        try {
            List<DefVo> list  = huorongService.getDefCenter();
            return RetResponse.makeOKRsp(list);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }


    @ApiOperation("执行日志")
    @GetMapping("/testLog")
    @ResponseBody
    public BaseResult testLog() {
        try {

            taskService.sysLog();
            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }
}
